import {
	defineConfig
} from 'vite'
import uni from '@dcloudio/vite-plugin-uni' // 引用官方插件

// 输出当前的环境变量
// console.log(process.env.NODE_ENV)

export default defineConfig({
	plugins: [
		uni()
	],
	server: {
		proxy: {
			// '/api1/wms': {
			// 	target: "http://10.1.13.44:6001", // 目标服务
			// 	changeOrigin: true,
			// 	rewrite: path => path.replace(/^\/api1\/wms/, '/wms'),
			// 	bypass: (req, res, options) => {
			// 		// 记录真实请求的地址
			// 		req.headers['X-Real-Host'] = options.target + options.rewrite(req.url)
			// 		res.setHeader('X-Real-Host', options.target + options.rewrite(req.url))
			// 	}
			// },
			'/api2': {
				target: "http://172.16.100.133:9999", // 目标服务
				changeOrigin: true,
				rewrite: path => path.replace(/^\/api2/, ''),
				bypass: (req, res, options) => {
					// 记录真实请求的地址
					req.headers['X-Real-Host'] = options.target + options.rewrite(req.url)
					res.setHeader('X-Real-Host', options.target + options.rewrite(req.url))
				}
			},
			'/api1/report': {
				target: "http://172.16.100.133:6003", // 目标服务
				changeOrigin: true,
				rewrite: path => path.replace(/^\/api1\/report/, '/report'),
				bypass: (req, res, options) => {
					// 记录真实请求的地址
					req.headers['X-Real-Host'] = options.target + options.rewrite(req.url)
					res.setHeader('X-Real-Host', options.target + options.rewrite(req.url))
				}
			},
			'/api1': {
				target: "http://172.16.100.133", // 目标服务
				changeOrigin: true,
				rewrite: path => path.replace(/^\/api1/, '/api'),
				bypass: (req, res, options) => {
					// 记录真实请求的地址
					req.headers['X-Real-Host'] = options.target + options.rewrite(req.url)
					res.setHeader('X-Real-Host', options.target + options.rewrite(req.url))
				}
			}
		}
	}
})
